package com.packt.webstore.domain.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.packt.webstore.domain.Customer;
import com.packt.webstore.domain.repository.CustomerRepository;

@Repository
public class InMemoryCustomerRepository implements CustomerRepository {
	
private List<Customer> listOfCustomers = new ArrayList<Customer>();
	
	public InMemoryCustomerRepository(){
		
		Customer customer = new Customer();
		
		customer.setName("Leandro Soares");
		customer.setAddress("Rua Alipio mendes numero C3, quadra 9 lote 7, Goiania, GO");
		customer.setNoOfOrdersMade(000003);
		
		listOfCustomers.add(customer);
		
	}
	
	public List<Customer> getAllCustomers() {
		
		return listOfCustomers;
	}
	
	public Customer getCustomerById(String customerId){
		Customer customerById = null;
		
		for(Customer customer : listOfCustomers){
			if(customer != null && customer.getCustomerId() != null &&
					customer.getCustomerId().equals(customerId)){
				 customerById = customer;
				break;
			}
		}
		
		if(customerById == null){
			throw new IllegalArgumentException("No customers found with the customer id: " + customerId);
		}
		
		return customerById;
	}

}
